﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using GameEditor.View.Components;
using GameEngine.View.Components;
using GameEngine.Model.Data;

namespace SilverlightClientEditor.View.Components
{
    public partial class WorldPropertiesEditorUC : UserControl, IWorldEditorMenuView<int>
    {
        public string WorldName
        {
            get { return NameTextBox.Text; }
            set { NameTextBox.Text = value; }
        }

        public string NewThingName
        {
            get { return ThingNameTextBox.Text; }
            set { ThingNameTextBox.Text = value; }
        }

        public WorldPropertiesEditorUC()
        {
         
            InitializeComponent();
            ThingTypeComboBox.DisplayMemberPath = "Name";
         
            //EditWorldButton.Tag = ILevelEditorMenuViewConstants.ButtonTags.EDITWORLD;
            NewThingButton.Tag = IWorldEditorMenuViewConstants.ButtonTags.NEWTHING;
            RemoveThingButton.Tag = IWorldEditorMenuViewConstants.ButtonTags.REMOVETHING;
            EditThingButton.Tag = IWorldEditorMenuViewConstants.ButtonTags.EDITTHING;           
        }

        public void AddThingType(IThingTypeVOId id)
        {
            ThingTypeComboBox.Items.Add(id);
            if (ThingTypeComboBox.SelectedItem == null)
                ThingTypeComboBox.SelectedItem = id;
        }
        public void RemoveThingType(IThingTypeVOId id) { ThingTypeComboBox.Items.Remove(id); }
        public List<IThingTypeVOId> GetThingTypes()
        {
            List<IThingTypeVOId> result = new List<IThingTypeVOId>();
            foreach (var obj in ThingTypeComboBox.Items)
            {
                result.Add(obj as IThingTypeVOId);
            }
            return result;
        }

        public IThingTypeVOId SelectedThingType
        {
            get { return ThingTypeComboBox.SelectedItem as IThingTypeVOId; }
        }

        public void AddThing(IThingVOId<int> id)
        {
            EditThingComboBox.Items.Add(id);
            if (EditThingComboBox.SelectedItem == null)
                EditThingComboBox.SelectedItem = id;
        }
        public void RemoveThing(IThingVOId<int> id) { EditThingComboBox.Items.Remove(id); }
        public List<IThingVOId<int>> GetThings()
        {
            List<IThingVOId<int>> result = new List<IThingVOId<int>>();
            foreach (var obj in EditThingComboBox.Items)
            {
                result.Add(obj as IThingVOId<int>);
            }
            return result;
        }
        public IThingVOId<int> SelectedThing
        {
            get { return EditThingComboBox.SelectedItem as IThingVOId<int>; }
        }


        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Button button = (Button)sender;
            if (OnExternalActionButtonClick != null)
                OnExternalActionButtonClick((IWorldEditorMenuViewConstants.ButtonTags)button.Tag);
        }

        public event OnButtonClickHandler<IWorldEditorMenuViewConstants.ButtonTags> OnExternalActionButtonClick;
    }
}
